class DefaultAuth < ActiveRecord::Migration
  def self.create_permission(name, role, level)
    Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
  end
  
  def self.up
    User.new({'login'=>'super','password'=>'super','password_confirmation'=>'super', 'email'=>'super@email.com', 'role'=>'super'}).save!
    
self.create_permission('create:site','super','1');
self.create_permission('view:site','super','1');
self.create_permission('edit:site','super','1');
self.create_permission('delete:site','super','1');
self.create_permission('create:group','super','1');
self.create_permission('view:group','super','1');
self.create_permission('edit:group','super','1');
self.create_permission('update:group','super','1');
self.create_permission('delete:group','super','1');
self.create_permission('create:runner','super','1');
self.create_permission('view:runner','super','1');
self.create_permission('edit:runner','super','1');
self.create_permission('delete:runner','super','1');
self.create_permission('create:entries','super','1');
self.create_permission('view:entries','super','1');
self.create_permission('edit:entries','super','1');
self.create_permission('delete:entries','super','1');
self.create_permission('create:incentives','super','1');
self.create_permission('view:incentives','super','1');
self.create_permission('edit:incentives','super','1');
self.create_permission('delete:incentives','super','1');
self.create_permission('create:user','super','1');
self.create_permission('view:user','super','1');
self.create_permission('edit:user','super','1');
self.create_permission('delete:user','super','1');
self.create_permission('create:runner','coord','2');
self.create_permission('view:runner','coord','2');
self.create_permission('edit:runner','coord','2');
self.create_permission('delete:runner','coord','2');
self.create_permission('create:group','coord','2');
self.create_permission('view:group','coord','2');
self.create_permission('edit:group','coord','2');
self.create_permission('delete:group','coord','2');
self.create_permission('update:group','coord','2');
self.create_permission('view:site','coord','2');
self.create_permission('create:entries','coord','2');
self.create_permission('view:entries','coord','2');
self.create_permission('edit:entries','coord','2');
self.create_permission('delete:entries','coord','2');
self.create_permission('view:incentives','coord','1');
self.create_permission('create:runner','lead','3');
self.create_permission('view:runner','lead','3');
self.create_permission('edit:runner','lead','3');
self.create_permission('delete:runner','lead','3');
self.create_permission('create:group','lead','1');
self.create_permission('edit:group','lead','3');
self.create_permission('delete:group','lead','3');
self.create_permission('update:group','lead','3');
self.create_permission('view:site','lead','2');
self.create_permission('create:entries','lead','3');
self.create_permission('view:entries','lead','3');
self.create_permission('edit:entries','lead','3');
self.create_permission('delete:entries','lead','3');
self.create_permission('view:incentives','lead','1');
self.create_permission('edit:site','coord','2');
self.create_permission('update:site','coord','2');
self.create_permission('view:group','lead','3');

  end

  def self.down
    User.destroy_all
    Permission.destroy_all
  end
end
